package com.test.rabbitmq.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {
    public static final String DEFAULT_TEST_QUEUE ="dev.book.register.queue";
    //public static final String DEFAULT_TEST_QUEUE ="default_test_queue";
    public static final String MANUAL_TEST_QUEUE = "manual_test_queue";

    @Bean("directQueue")
    public Queue directQueue(){
        return new Queue("default_test_queue",false,false,true);
    }

    @Bean("directExchange")
    public Exchange directExchange(){
        return new DirectExchange("default_test_exchange",false,true);
    }

    @Bean
    public Binding directQueueBingingExchange(@Qualifier("directQueue") Queue queue,@Qualifier("directExchange") Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("test.default").noargs();
    }



    @Bean("directQueueManual")
    public Queue directQueueManual(){
        return new Queue("manual_test_queue",false,false,true);
    }

    @Bean("directExchangeManual")
    public Exchange directExchangeManual(){
        return new DirectExchange("manual_test_exchange",false,true);
    }

    @Bean
    public Binding directQueueBingingExchangeManual(@Qualifier("directQueueManual") Queue queue, @Qualifier("directExchangeManual")Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("test.manual").noargs();
    }




    @Bean("fanoutQueue1")
    public Queue fanoutQueue1(){
        return new Queue("fanout_test_queue1",false,false,true);
    }

    @Bean("fanoutQueue2")
    public Queue fanoutQueue2(){
        return new Queue("fanout_test_queue2",false,false,true);
    }

    @Bean("fanoutExchange")
    public Exchange fanoutExchange(){
        return new FanoutExchange("fanout_test_exchange",false,true);
    }

    @Bean
    public Binding fanoutQueueBingingExchange1(@Qualifier("fanoutQueue1") Queue queue,@Qualifier("fanoutExchange") Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("").noargs();
    }

    @Bean
    public Binding fanoutQueueBingingExchange2(@Qualifier("fanoutQueue2") Queue queue,@Qualifier("fanoutExchange") Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("").noargs();
    }

    @Bean("topicMessage")
    public Queue topicQueue1(){
        return new Queue("topic_test_message",false,false,true);
    }

    @Bean("topicNote")
    public Queue topicQueue2(){
        return new Queue("topic_test_note",false,false,true);
    }

    @Bean("topicExchange")
    public Exchange topicExchange(){
        return new TopicExchange("topic_test_exchange",false,true);
    }

    @Bean
    public Binding topicBindingExchange1(@Qualifier("topicMessage") Queue queue,@Qualifier("topicExchange") Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("topic.test.message").noargs();
    }

    @Bean
    public Binding topicBindingExchange2(@Qualifier("topicNote") Queue queue,@Qualifier("topicExchange") Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("topic.test.#").noargs();
    }

    @Bean("routingQueue1")
    public Queue routingQueue1(){
        return new Queue("routing_test_info",false,false,true);
    }

    @Bean("routingQueue2")
    public Queue routingQueue2(){
        return new Queue("routing_test_infoAndError",false,false,true);
    }

    @Bean("routingExchange")
    public Exchange routingExchange(){
        return new DirectExchange("routing_test_exchange",false,true);
    }

    @Bean
    public Binding routingBindingExchange1(@Qualifier("routingQueue1") Queue queue,@Qualifier("routingExchange") Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("info").noargs();
    }

    @Bean
    public Binding routingBindingExchange2(@Qualifier("routingQueue2") Queue queue,@Qualifier("routingExchange") Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("info").noargs();
    }
    @Bean
    public Binding routingBindingExchange3(@Qualifier("routingQueue2") Queue queue,@Qualifier("routingExchange") Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("error").noargs();
    }
}
